package api

import (
	"gin-products/api/handler"
	"gin-products/consts"
	"github.com/gin-gonic/gin"
	jwt "github.com/golangblogs/gojwt"
)

func LoadRouter(r *gin.Engine) {
	api := r.Group("/api")
	{
		user := api.Group("/user")
		{
			user.POST("/register", handler.Register)
			user.POST("/login", handler.Login)
			user.Use(jwt.JWTAuth(consts.JWT_SECRET_KEY))
			user.POST("/RefreshToken", handler.RefreshToken)
			//
		}

		product := api.Group("/product")
		{
			product.POST("/AddProduct", handler.AddProduct)
			product.POST("/UpdateProduct", handler.UpdateProduct)
			product.POST("/DelProduct", handler.DelProduct)
			product.POST("/GetProduct", handler.GetProduct)
		}

		order := api.Group("/order")
		{
			//order.Use(jwt.JWTAuth(consts.JWT_SECRET_KEY))
			order.POST("/AddOrder", handler.AddOrder)
			order.POST("/UpdateOrder", handler.UpdateOrder)
			order.POST("/DelOrder", handler.DelOrder)
			order.POST("/GetOrder", handler.GetOrder)
		}
		comment := api.Group("/comment")
		{
			comment.POST("/AddComment", handler.AddComment)
			comment.POST("/UpdateComment", handler.UpdateComment)
			comment.POST("/DelComment", handler.DelComment)
			comment.POST("/GetComment", handler.GetComment)
		}
	}
}
